package pathAlgorithms;

import javax.vecmath.Point2d;
import program.RoboMap;

public class RoboGraphTime extends RoboGraph{
	
	/**
	 * @param map
	 * @param time
	 */
	public RoboGraphTime(RoboMap map, double time) {
		super(map, time);
	}
	
	protected RoboNode addNodeIfValid(double x, double y, RoboPath path, RoboNode goalNode) {
		
		if(x > xSize || y > ySize || x < -xSize || y < -ySize) {
			return null;
		}
		
		Point2d point = new Point2d(x,y);
		double  timeSpent = path.getPathLength();
		RoboMap.Content content = roboMap.getContentFromPosition(point, time + timeSpent);
		
		if(content != RoboMap.Content.OBJECT && !visited.contains(point)) {
			RoboNode node = new RoboNode(point,content);
			graphLogger.nodesCreated++;
			
			double distance = distance(node,goalNode);
			
			if(content == RoboMap.Content.MAYBEOBJECT) {
				distance *= maybeObjectFactor;
			}

			RoboPath newPath = new RoboPath(path,node,distance);
			graphLogger.pathsCreated++;
			
			queue.add(newPath);
			graphLogger.pathsAddedToQue++;
			
			return node;
		}else {
			return null;
		}
		
	}	
}
